#include <stdint.h>
#include "StringHelpers.h"

namespace Helpers{
    namespace StringHelpers{
        uint32_t GetLength(char* str){
            uint32_t count=0;
            while(*str!='\0'){
                count++;
                str++;
            }
            return 0;
        }

        void Reverse(char* string, uint32_t length){
            char tmp;
            uint32_t i=0, j=length-1;
            while(i<length/2){
                tmp=string[i];
                string[i]=string[j];
                string[j]=tmp;
                i++;
                j--;
            }
        }

        void IntToString(int number, uint8_t base, char* output){
            char characters[] = "0123456789ABCDEF";
            uint8_t negative=0;
            if(number<0){
                negative=1;
                number=-number;
            }
            uint32_t i=0;
            while(number>0){
                output[i]=characters[number%base];
                number=number/base;
                i++;
            }
            if(negative){
                output[i]='-';
                i++;
            }
            Reverse(output, i);
            output[i]='\0';
        }
    }
}
